package generator.website;

import java.util.Iterator;
import org.eclipse.emf.common.util.EList;
import turtle.*;;

public class SimpleToHTML
{
  protected static String nl;
  public static synchronized SimpleToHTML create(String lineSeparator)
  {
    nl = lineSeparator;
    SimpleToHTML result = new SimpleToHTML();
    nl = null;
    return result;
  }

  public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
  protected final String TEXT_1 = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">" + NL + "<html>" + NL + "\t<head> <title> Stage Description</title>" + NL + "\t\t<meta name=\"language\" content=\"en\">" + NL + "\t\t<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\">" + NL + "\t</head>" + NL + "\t\t<body>" + NL + "\t\t<h1> List of Stage's Choreographies</h1>" + NL + "\t\t";
  protected final String TEXT_2 = NL + "\t\t\t" + NL + "\t\t\t" + NL + "\t\t\t" + NL + "\t\t\t" + NL + "\t\t\t<h4>";
  protected final String TEXT_3 = "</h4>" + NL + "\t\t\t" + NL + "\t\t" + NL + "\t\t";
  protected final String TEXT_4 = NL + "\t\t" + NL + "\t\t<p><i>Action Num ";
  protected final String TEXT_5 = " : <u><b>";
  protected final String TEXT_6 = "</b></u>. Target Turtle:</i> ";
  protected final String TEXT_7 = "</p>" + NL + "\t\t" + NL + "\t\t" + NL + "\t\t\t\t\t" + NL + "\t\t";
  protected final String TEXT_8 = NL + "\t</body>" + NL + "</html>";

  public String generate(Object argument)
  {
    final StringBuffer stringBuffer = new StringBuffer();
     Stage stage = (Stage) argument; 
    stringBuffer.append(TEXT_1);
    
		
		
		Choreography cho;
		ActionBase act;
		int choreographyNo = 0;
		int actionNo;
		String actionType = "";
		String choString = "";
		String actionString = "";
		EList<Choreography> listChoreography = stage.getChoreographies();
		for (Iterator<Choreography> i = listChoreography.iterator(); i.hasNext();)
		{
			cho = i.next();
			choreographyNo++;
			actionNo = 0;   
			choString = "Choreography Num " + choreographyNo + ": " + cho.getName();
			                                                 
		
    stringBuffer.append(TEXT_2);
    stringBuffer.append(choString);
    stringBuffer.append(TEXT_3);
    	
			for (Iterator<ActionBase> j = cho.getActions().iterator(); j.hasNext();)
			{
				actionNo ++;
				act = j.next();
				if (act instanceof ActionFoward)
					actionType = "Foward";
				if (act instanceof ActionRotate)
					actionType = "Rotate";
				if (act instanceof ActionSetPen)
					actionType = "SetPen";
				actionString = "Action Num " + actionNo + ": " + actionType + ". Target Turtle: " + act.getTarget().getName();
		
    stringBuffer.append(TEXT_4);
    stringBuffer.append(actionNo);
    stringBuffer.append(TEXT_5);
    stringBuffer.append(actionType);
    stringBuffer.append(TEXT_6);
    stringBuffer.append(act.getTarget().getName());
    stringBuffer.append(TEXT_7);
    		
			}
		}
		
		
    stringBuffer.append(TEXT_8);
    return stringBuffer.toString();
  }
}
